﻿#include "library.au3"

Global $win = "League of Legends (TM) Client"
Global $hWnd = WinActivate($win)
Global $winPos = WinGetPos($win)

Global $attackSpeed = 0.75
Global $shotRatio = 0.3
Global $range = 65
Global $height = 20

FFSetWnd($hWnd, False)

Global $mainTimer = TimerInit()
Global $mainDiff = 0
Global $keyAPressed = 0
Global $keyBPressed = 0
Global $keyCPressed = 0

Global $hDLL = DllOpen("user32.dll")
Main()
DllClose($hDLL)

Func Main()
   While True
	  Sleep(1)

	  $hWnd = WinActive($win)
	  If $hWnd = 0 Then
		 ContinueLoop
	  EndIf

	  If _IsPressed("51", $hDLL) = 1 Then
		 If $keyAPressed = 0 Then
			AutoHit(200)
		 EndIf
		 $keyAPressed = 1
	  Else
		 $keyAPressed = 0
	  EndIf

	  If _IsPressed("57", $hDLL) = 1 Then
		 If $keyBPressed = 0 Then
			Send("{1 2}")
		 EndIf
		 $keyBPressed = 1
	  Else
		 $keyBPressed = 0
	  EndIf

	  If _IsPressed("52", $hDLL) = 1 Then
		 If $keyCPressed = 0 Then
			Send("{2 2}")
		 EndIf
		 $keyCPressed = 1
	  Else
		 $keyCPressed = 0
	  EndIf

   WEnd
EndFunc

Func AutoHit($dealy)
   Sleep(200)

   Local $mousePos = MouseGetPos()
   Local $groundPos = [$mousePos[0], $mousePos[1] + 70]

   Send("{` down}")
   MouseClick("right", $groundPos[0], $groundPos[1], 2, 0)
   Send("{` up}")
   MouseMove($mousePos[0], $mousePos[1], 0)

   Sleep($dealy)

   FFSnapShot(50, 50, $winPos[2] - 50, $winPos[3] - 120)

   Local $heroPos[2]
   Local $heroFind = FindHero($heroPos[0], $heroPos[1], $hWnd)

   Local $enemyPos[2]
   Local $enemyFind = FindEnemy($enemyPos[0], $enemyPos[1], $hWnd)

   If $heroFind = False Then
	  Return
   EndIf

   $mousePos = MouseGetPos()

   Local $curRange = 0
   Local $curDist = 0
	Local $checkRange = CheckRange($heroPos[0], $heroPos[1], $enemyPos[0], $enemyPos[1], $range, $height, $curRange, $curDist)
	; ToolTip("curRange:"&Int($curRange)&" curDist:"&Int($curDist), $winPos[0] + 100, $winPos[1] + 5)

   If ($heroFind And $enemyFind And $checkRange) Then
	  Send("{` down}")
	  MouseClick("right", $enemyPos[0], $enemyPos[1], 2, 0)
	  Send("{` up}")
   Else
	  MouseClick("right", $mousePos[0], $mousePos[1], 2, 0)
   EndIf

EndFunc
